var dateType = '1',  //日期类型
    dateStart = '', //开始日期
    dateEnd = '';   //结束日期
//用户选择开始
function selectSH(id) {
	var te = $("#SH").attr("btnType");
	if(te == "隐藏") {
		$("#SH").attr("btnType", "显示");
		$("#selectBox").fadeIn(600, function() {
			$("#selectBox").css("display", "block")
		})
	}
	if(te == "显示") {
		$("#SH").attr("btnType", "隐藏");
		$("#selectBox").fadeOut(600, function() {
			$("#selectBox").css("display", "none")
		})
	}
}
//用户选择结束
//设置session参数
function setSessionfunc(typeid,zid,alarm){
	//设置当前用户的session值
    //typeid 系统分类id (比如对应前端八大类), zid 当前用户的站点id
	var url="/bigscrenn/setUserSession?typeid="+typeid+"&zid="+zid+"&cid="+alarm;
    $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
              console.log(data,'参数');         
	     }
    		
    });	
};
//进入页面先获取其实时间
//var sDate = $(".show input#test1").val();
//var eDate = $(".show input#test6").val();
var sDate;
var eDate;
var userID='',zID=''; //定义全局的用户id站点id
var vm;
//energyVUEFunc();
setTimeout(energyVUEFunc,456);
function energyVUEFunc(){
	sDate = $(".show input#test1").val();
	eDate = $(".show input#test6").val();
	
	vm = new Vue({
		el:"#app",
		data:{
			userid : "",   //用户id
			unitID : "",   //单位id
			userType : "", //用户类型
			kehu : [],     //左边列表
			zid : "",      //站点
			zName:'',       //站点名称
		    danweiID:'',    //单位id
		    danweiName:'',   //单位名称
		},
		mounted:function(){
			this.getSession();
		},
		methods:{
			//session
			getSession:function(){
				var vs = this;
				var userid,unitID,userType;
				var url="/bigscrenn/getUserSession";
			     $.ajax({
				     cache: false,
				     type: "POST",
				     url:url,
				     data:"",
				     async: false,				   
				     success: function(data){
				    	 console.log("session数据：",data);
				    	 //js解析json串
			     	     var obj = JSON.parse(data);
			             if (obj.session.length>0){
			                   /*alert(obj.session[0].UserID);//用户id
			                   alert(obj.session[0].Name);//用户名称
			                   alert(obj.session[0].UnitID);//用户单位id
			                   alert(obj.session[0].UserAuthority);//用户权限 2 所有单位 3 本单位
			                   alert(obj.session[0].typeid);//系统分类id (比如对应前端八大类)
			                   alert(obj.session[0].zid);//当前用户的站点id*/
			            	   vs.userid = obj.session[0].UserID;
			 	  			   vs.unitID = obj.session[0].UnitID;
			 	  			   vs.userType = obj.session[0].UserAuthority;
			 	  			   //vs.zid = obj.session[0].zid;
			 	  			   
			 	  			   
			 	  			   console.log("进来session userID="+userID+"and zID="+zID) ;
			 	  			   
			 	  			   vs.danweiID = (obj.session[0].cid1).split(",")[0];  //单位id方法
			 	  			   vs.danweiName = (obj.session[0].cid1).split(",")[1];//上页选中来的单位名称
			 	  			   
			 	  			   //vs.zid = obj.session[0].zid;
			 	  			   vs.zid = (obj.session[0].zid).split(",")[0];  //站点id
			 	  			   vs.zName = (obj.session[0].zid).split(",")[1];//上页选中来的站点名称
			 	  			   //alert("告警统计 vs.danweiID="+vs.danweiID + " vs.danweiName= "+vs.danweiName +"vs.zid = "+vs.zid +"vs.zName = "+vs.zName);
			 	  			   $('#topTitle').text(vs.zName);
			 	  			   
			 	  			   zhandianid = vs.zid;
			 	  			   onlineFunc();
			 	  			   
			 	  			   console.log("站点id="+vs.zid);
			 	  			   //setSessionfunc('',vs.zid+','+vs.zName,'',(vs.danweiID+','+vs.danweiName));     // session存站点（第二个参）
			 	  			   
			 	  			   userID = obj.session[0].UserID;//给全局userid赋值
			 	  			   zID = vs.zid; //给全局unitid赋值
			 	  			   localStorage.setItem("userid", obj.session[0].UserID);
			 	  			   localStorage.setItem("zID", obj.session[0].zid);
			            	 }
			                 //alert("userid="+vs.userid+"and unitID="+vs.unitID+"and userType="+vs.userType+"vs.zid="+vs.zid + "全局zID = "+zID) ;
			               //参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
			                 //var url="/bigscrenn/getMWarningZS?userid=0100000000000004&unitid=000000000001&type=1&sdate=2018-12-21&edate=";
			                 
			                 var url1="/bigscrenn/getMWarningZS?userid="+vs.userid+"&unitid="+vs.zid+"&type=1&sdate="+($(".show input").val())+"&edate=";
			                 //alert("url1="+url1);
			                 gjZoushiFunc(url1);
			                 
			                 if(vs.danweiID==undefined||vs.danweiID==''){
			                	 vs.danweiID=vs.unitID;
			                 }
			                 vs.getUnitIData(vs.userid,vs.danweiID);
			                
			                //具体用户进来的操作
			                if(vs.userType==3){
			                	console.log("我的身份是具体用户");
			                	$(".backHome-box >a").css("display","none");// “返回首页”隐藏
			                }
			                selectDateFunc(userID);//选中日期方法
				     }
			     });
			},
			//站点
			getUnitIData:function(sy_userid,sy_uniId){
				var unitData = this;
				// userid用户id,unitid单位id,unitid为空时表示调用多个单位的站点信息
			    var url="/bigscrenn/getSiteList?userid="+sy_userid+"&unitid="+sy_uniId;
			    //alert("url="+url);
			     $.ajax({
				     cache: true,
				     type: "POST",
				     url:url,
				     data:"",
				     async: false,				   
				     success: function(data){
                        //alert("站点列表="+data);
                       // js解析json串
                       var obj = JSON.parse(data);
                        //alert("记录数="+obj.total);//记录数
                       unitData.kehu = obj.rows;// 分类后的站点（用户）
                       // unitData.getPicData(obj.rows[0].CID);//电气图ID（进入页面时默认第一个站点的电气图）
                       // alert("========="+obj.rows[0].CID);
                       unitData.$nextTick(function() {
                    	   var arrr = $(".zhanDian");
                    	   // alert("arrr=="+arrr.length);
                    	   var firstACID = $(".zhanDian:first()").attr("cid");
                    	   localStorage.setItem("zID", firstACID);// 没有点击存储本页第一个的站点CID覆盖homecid
                    	   var thisCid="";
                    	   for (var n=0;n<arrr.length;n++){
                    		   arrr[n].index = n;
                    		   arrr[n].onclick = function(){
                    			   //alert($(this).text());
                    			   
                    			   thisCid = $(this).attr("cid");
                    			   console.log("thisCid="+thisCid);
                    			   setSessionfunc('',thisCid+','+$(this).text(),'',(unitData.danweiID+','+unitData.danweiName));     // session存站点（第二个参）
                    			   
	                        	   window.location.href = "./specificUser.html";// 返回具体页面
                    		   }
                    		   
                    	   }
                       });
				     }
			     });
			},
		},
	})
}



//按天，按月，按年，查询 开始
function func(){
	//$("#EARankTableBox").html('');//告警排行清空
	if($(".show >input").length==1){
		dateStart = $(".show input").val();
		dateEnd = '';
	}
	if($(".show >input").length==2){
		dateStart = $(".show input").eq(0).val();
		dateEnd = $(".show input").eq(1).val();
	}
	
	
	var t_dateType = $(".xz").find("input").attr("dateType"); // 获取选中日期类型type，
	
	var chaxunURL="/bigscrenn/getMWarningTG?userid="+userID+"&unitid="+zID+"&type="+t_dateType+"&sdate="+dateStart+"&edate="+dateEnd;
	console.log("开始时间 dateStart ="+dateStart+"  结束时间 dateEnd="+dateEnd);
	//alert("查询地址chaxunURL="+chaxunURL);
	pieAlarmFunc(chaxunURL);
	
	//==点击查询对告警走势操作
	var gjZSURL="/bigscrenn/getMWarningZS?userid="+userID+"&unitid="+zID+"&type="+t_dateType+"&sdate="+dateStart+"&edate="+dateEnd;
	//alert("点击后告警走势地址gjZSURL="+gjZSURL);
	gjZoushiFunc(gjZSURL);
	
	//==点击查询对告警排行操作
	
	var gjRankurl="/bigscrenn/getMWarningPH?userid="+userID+"&unitid="+zID+"&type="+t_dateType+"&sdate="+dateStart+"&edate="+dateEnd;
	//alert("点击查询对告警排行="+gjZSURL);
	gjPaihangFunc(gjRankurl);
	
	//==点击查询对告明细行操作
	var gtype = $('.act').attr('gtype');
	var gjDetailTapurl="/bigscrenn/getMWarningMX?userid="+userID+"&unitid="+zID+"&type="+t_dateType+"&sdate="+dateStart+"&edate="+dateEnd+"&gtype="+gtype;
    gjDetailFunc(gjDetailTapurl);
}
function selectDateFunc(userid) {
	$(".am-radio-inline").removeClass('xz');
	$(".am-radio-inline").eq(0).addClass('xz');
	var userID;
	//alert("userid = "+userid);
	userID = userid;
	
	if($(".show >input").length==1){
		dateStart = $(".show input").val();
		dateEnd = '';
	}
	if($(".show >input").length==2){
		dateStart = $(".show input").eq(0).val();
		dateEnd = $(".show input").eq(1).val();
	}
	//alert("dateStart =: "+dateStart +" dateEnd =: "+dateEnd);
	
	
	//饼图数据默认接口
	//参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
    var url="/bigscrenn/getMWarningTG?userid="+userID+"&unitid="+zID+"&type=1&sdate="+dateStart+"&edate=";
    pieAlarmFunc(url);
    
    //告警占比默认
    var ZSDefalturl="/bigscrenn/getMWarningZS?userid="+userID+"&unitid="+zID+"&type=1&sdate="+dateStart+"&edate=";
    //alert("ZSDefalturl="+ZSDefalturl);
    gjZoushiFunc(ZSDefalturl);
    
    //告警排行默认
    var rankDefaulturl="/bigscrenn/getMWarningPH?userid="+userID+"&unitid="+zID+"&type=1&sdate="+dateStart+"&edate=";
    gjPaihangFunc(rankDefaulturl);
    
    //告警明细默认
    var detailDefaulturl="/bigscrenn/getMWarningMX?userid="+userID+"&unitid="+zID+"&type=1&sdate="+dateStart+"&edate="+dateEnd+"&gtype=0";
    //alert("detailDefaulturl = "+detailDefaulturl);
    gjDetailFunc(detailDefaulturl);
    localStorage.setItem("gj_type",1); //存储type，传给点击查询/严重、普通、全部
    secondLiTab = $(".am-radio-inline");
	secondLiTab.click(function() {
		var index = secondLiTab.index(this);
		$(".am-radio-inline").removeClass('xz');
		$(".am-radio-inline").eq(index).addClass('xz');
		
		
		//alert("index = "+index);
		//获取日期时间
		if($(".show >input").length==1){
			dateStart = $(".show input").val();
			dateEnd = '';
		}
		if($(".show >input").length==2){
			dateStart = $(".show input").eq(0).val();
			dateEnd = $(".show input").eq(1).val();
		}
		//获取日期时间类型
		dateType = $('.xz >input').attr('dateType');
		
		
		//alert(" dateType == " + dateType + " dateStart= "+dateStart +"  dateEnd= "+dateEnd);
		
		var gjURL="/bigscrenn/getMWarningTG?userid="+userID+"&unitid="+zID+"&type="+dateType+"&sdate="+dateStart+"&edate="+dateEnd;
		//alert("点击后地址gjURL="+gjURL);
		pieAlarmFunc(gjURL);
		
		//==点击日期对告警走势操作
		var gjZSURL="/bigscrenn/getMWarningZS?userid="+userID+"&unitid="+zID+"&type="+dateType+"&sdate="+dateStart+"&edate="+dateEnd;
		//alert("点击后告警走势地址gjZSURL="+gjZSURL);
		gjZoushiFunc(gjZSURL);
		
		//==点击日期对告警排行操作
		//参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
	    var gjRankCXDateurl="/bigscrenn/getMWarningPH?userid="+userID+"&unitid="+zID+"&type="+dateType+"&sdate="+dateStart+"&edate="+dateEnd;
	    gjPaihangFunc(gjRankCXDateurl);
	    
	    //==点击日期对告警明细操作
	    var gtype = $('.act').attr('gtype');
	    
	    var gjDetailCXurl="/bigscrenn/getMWarningMX?userid="+userID+"&unitid="+zID+"&type="+dateType+"&sdate="+dateStart+"&edate="+dateEnd+"&gtype="+gtype;
	    //alert("点击日期对告警明细url="+gjDetailCXurl);
	    gjDetailFunc(gjDetailCXurl);
	});
}

//告警明细ajax开始
//得到指定站点的告警明细(非首页使用);

//点击 一般、报警、跳闸 按钮
$(".mx-btn").removeClass('act');
$(".mx-btn").eq(0).addClass('act');
var btnType = $(".button-box >button");
btnType.click(function() {
	var index = $(this).index();
	$(".mx-btn").removeClass('act');
	$(".mx-btn").eq(index).addClass('act');
	if($(".show >input").length==1){
		dateStart = $(".show input").val();
		dateEnd = '';
	}
	if($(".show >input").length==2){
		dateStart = $(".show input").eq(0).val();
		dateEnd = $(".show input").eq(1).val();
	}
	var dateType = $('.xz').find('input').attr("dateType"); // 获取选中日期类型type，
	//alert("dateType = "+dateType);
	
	var userID;
	var zID;
	//alert("vm.zid = "+vm.zid + " vm.userid = "+vm.userid);
	zID = vm.zid;
	userID = vm.userid;
	
	dateType = $(".xz").find("input").attr("dateType"); //获取点击日期gj_type，
	var gType = "";
	var indexBtn = btnType.index(this);
	if(indexBtn==0){
		gType = "0";
		console.log("gType="+gType);
	}
	if(indexBtn==1){
		gType = "1";
		console.log("gType="+gType);
	}
	if(indexBtn==2){
		gType = "2";
		console.log("gType="+gType);
	}
	if(indexBtn==3){
		gType = "3";
		console.log("gType="+gType);
	}
	localStorage.setItem("gType",gType); //存储btn类型，传给点击查询
	var urlGtype="/bigscrenn/getMWarningMX?userid="+userID+"&unitid="+zID+"&type="+dateType+"&sdate="+dateStart+"&edate="+dateEnd+"&gtype="+gType;
	//alert("url+gtype="+urlGtype);
	gjDetailFunc(urlGtype);
})
//gjDetailFunc();
function gjDetailFunc(url){
	//alert("进来的详情接口="+url);
	var gjDetailArr = [];
    //参数userid用户id,unitid站点id,type日期类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2 ,gtype 0全部 1普通2严重
    //var url="/bigscrenn/getMWarningMX?userid=0100000000000004&unitid=000000000001&type=4&sdate=2017&edate=2018&gtype=2";
	$.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
           //alert("告警明细数据=："+data);
           //js解析json串
	       if(data && data != '' && data != null && data != undefined){
	    	   var obj = JSON.parse(data);
	           for (var i=0;i<obj.rows.length;i++){
	        	     /*alert(obj.rows[i].DATETIME);//时间
	                 alert(obj.rows[i].WTITLE);//标题
	                 alert(obj.rows[i].WCONTENT);//内容*/
	        	   gjDetailArr.push({
	        		   "id": obj.rows[i].DATETIME,
						"deptName": obj.rows[i].WCONTENT,
						"company": obj.rows[i].WTITLE,
	        	   })
	           }
	       }
	       alarmStyleFunc(gjDetailArr);
	     }
     });
     
}

//告警明细Ajax结束

//告警排行ajax开始
//得到指定站点的告警排行(非首页使用)
//gjPaihangFunc();
function gjPaihangFunc(url){
	//alert("进来的rankUrl="+url);
	var rankArr = [];
    //参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
    //var url="/bigscrenn/getMWarningPH?userid=0100000000000004&unitid=000000000001&type=1&sdate=2018-12-21&edate=";
     $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
           //alert("告警排行数据="+data);
           //js解析json串
	       if(data && data!='' && data!=null && data!=undefined){
	    	   var obj = JSON.parse(data);
	           for (var i=0;i<obj.rows.length;i++){
	        	     /*alert(obj.rows[i].CODE);//序号
	                 alert(obj.rows[i].ITEM);//类别
	                 alert(obj.rows[i].NUM);//数据*/
	        	     rankArr.push({
	        	    	"rank": obj.rows[i].CODE,
	     				"time":obj.rows[i].ITEM,
	     				"number": obj.rows[i].NUM
	        	     })
	        	     
	           }
	       }
	       if(rankArr==null||rankArr==undefined){
	      	 $("#EARankTableBox").html('');
	       }else{
	      	 $("#EARankTableBox").html('<table id="EARankTable" ></table>');
	      	 alarmRankFunc(rankArr)
	       }
	     }
     });
     
     
}
//告警排行ajax结束


//告警统计饼图
//得到指定站点的告警统计(非首页使用)
function pieAlarmFunc(url){
	var pieAlarmArr = [];
    //参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
    //var url="/bigscrenn/getMWarningTG?userid=0100000000000004&unitid=000000000001&type=1&sdate=2018-12-21&edate=";
     $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
           //alert("告警统计饼图数据="+data);
           //js解析json串
           if(data && data!='' && data!=null && data!=undefined){
        	   var obj = JSON.parse(data);
               for (var i=0;i<obj.rows.length;i++){
                     //alert(obj.rows[i].GJNAME);//类别
                    // alert(obj.rows[i].NUM);//数据
            	   	pieAlarmArr.push({"name":obj.rows[i].GJNAME,"value":obj.rows[i].NUM});
               }
           }
           //alert("pieAlarmArr=="+pieAlarmArr);
           if(pieAlarmArr==''){
        	   pieAlarmArr.push({"value":0,"name":''})
           }
           alramTJFunc(pieAlarmArr);
	     }
         
     });
     
}
//环状图开始
function alramTJFunc(arr) {
	var healthChart = echarts.init(document.getElementById("alarmTJ"));
	var health_option = {
		title: {
			text: '',
			x: 'center',
			textStyle: {
				//文字颜色
				color: '#fff',
				//字体风格,'normal','italic','oblique'
				fontStyle: 'normal',
				//字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
				fontWeight: '100',
				//字体系列
				fontFamily: 'sans-serif',
				//字体大小
				fontSize: 20
			}
		},

		tooltip: {
			trigger: 'item',
			formatter: "{a} <br/>{b}: {c} ({d}%)"
		},
		legend: {
			orient: 'horizontal',
			x: 'center',
			y: 'bottom',
			itemGap: 30,
			data: ["一般事件","报警事件","跳闸事件"],
			textStyle: {
				//文字颜色
				color: '#fff',
				//字体风格,'normal','italic','oblique'
				fontStyle: 'normal',
				//字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
				fontWeight: '100',
				//字体系列
				fontFamily: 'sans-serif',
				//字体大小
				　　　　fontSize: 14
			}
		},
		series: [{
			name: '告警统计',
			type: 'pie',
			radius: ['50%', '70%'],
			avoidLabelOverlap: false,
			label: {
				normal: {
					show: false,
					position: 'center'
				},
				emphasis: {
					show: true,
					textStyle: {
						fontSize: '30',
						fontWeight: 'bold'
					}
				}
			},
			labelLine: {
				normal: {
					show: false
				}
			},
			data:arr,
			/*data: [{
				"name": "普通",
				"value": 234
			}, {
				"name": "严重",
				"value": 24
			}],*/
			itemStyle: {
				normal: {
					color: function(params) {
						//自定义饼图颜色
						var colorList = [
							'#0feb8b', '#ffa500','#ff0000'
						];
						return colorList[params.dataIndex]
					}
				}

			}
		}]
	};
	healthChart.setOption(health_option);
	$(document).ready(function() {
		healthChart.resize();
	});
	window.addEventListener("resize", function() {
		healthChart.resize();
	})
}
//环状图结束

//告警走势开始
//得到指定站点告警走势统计(非首页使用)
function gjZoushiFunc(url){
	//alert("进来的告警走势地址="+ url);
	var gj_Xarr = [],gj_yzArr=[],gj_ptArr=[],gj_tiaozhaArr=[];
	
	//参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
    //var url="/bigscrenn/getMWarningZS?userid=0100000000000004&unitid=000000000001&type=1&sdate=2019-04-01&edate=";
     $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
           console.log("-data-"+data);
           //js解析json串
           var obj = JSON.parse(data);
           
           for (var i=0;i<obj.frows.length;i++){
                 //alert(obj.frows[i].ITEM);//项目
                 //alert(obj.frows[i].DATA);//数据
        	     gj_Xarr.push(obj.frows[i].ITEM);
                 var obj1 = JSON.parse(obj.frows[i].DATA);
                 for (var j=0;j<obj1.rows.length;j++){
                     //alert(obj1.rows[j].NAME1);//一般事件
                     //alert(obj1.rows[j].VALUE1);//一般事件数据
                     //alert(obj1.rows[j].NAME2);//报警事件
                     //alert(obj1.rows[j].VALUE2);//报警事件数据      
                     //alert(obj1.rows[j].NAME3);//跳闸事件
                     //alert(obj1.rows[j].VALUE3);//跳闸事件数据 
                	 gj_ptArr.push(obj1.rows[j].VALUE1);
                	 gj_yzArr.push(obj1.rows[j].VALUE2);
	            	 gj_tiaozhaArr.push(obj1.rows[j].VALUE3);
                 }
           }
           alarmTongJiFunc(gj_Xarr,gj_ptArr,gj_yzArr,gj_tiaozhaArr);
	     }
     });
	
    //参数userid用户id,unitid站点id,type统计类别 1 按日统计2 按月统计 3 按年度统计 4 按多年度统计,sdate统计日期1,edate统计日期2
    //var url="/bigscrenn/getMWarningZS?userid=0100000000000004&unitid=000000000001&type=1&sdate=2018-12-21&edate=";
     /*$.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
           //alert("告警走势数据="+data);
           //js解析json串
	       if(data && data!='' && data!=null && data!=undefined){
	    	   var obj = JSON.parse(data);
	           
	           for (var i=0;i<obj.frows.length;i++){
	             //alert(obj.frows[i].ITEM);//项目
	             //alert(obj.frows[i].DATA);//数据
	        	   gj_Xarr.push(obj.frows[i].ITEM);
	             var obj1 = JSON.parse(obj.frows[i].DATA);
	             for (var j=0;j<obj1.rows.length;j++){
	                 //alert(obj1.rows[j].NAME1);//普通
	                  // alert(obj1.rows[j].VALUE1);//普通数据
	                  // alert(obj1.rows[j].NAME2);//严重
	                   //alert(obj1.rows[j].VALUE2);//严重数据
	            	 gj_yzArr.push(obj1.rows[j].VALUE2);
	            	 gj_ptArr.push(obj1.rows[j].VALUE1);
	             }
	             //alert("gj_yzArr="+gj_yzArr.length);
	           }
	       }
	       //alert("gj_Xarr="+gj_Xarr);
	       //alert("gj_ptArr="+gj_ptArr);
	       //alert("gj_yzArr="+gj_yzArr);
	       alarmTongJiFunc(gj_Xarr,gj_ptArr,gj_yzArr)
	     }
     });*/
     
}

function alarmTongJiFunc(time,trendData,trendData1,tiaozhaArr) {
	var myChart3 = echarts.init(document.getElementById('alarmTendId'));
	option3 = {
		backgroundColor: "rgb(0,0,0,.2)",
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				lineStyle: {
					color: '#57617B'
				}
			}
		},
		legend: {
			icon: 'rect',
			data: ["一般事件","报警事件","跳闸事件"],
			align: 'right',
			right: '2%',
			top: '5%',
			textStyle: {
				color: "#fff"
			},
			itemWidth: 30,
			itemHeight: 10,
			itemGap: 15
		},
		grid: {
			left: '1%',
			right: '2%',
			top: '20%',
			bottom: '5%',
			containLabel: true
		},
		xAxis: [{
			type: 'category',
			boundaryGap: false,
			axisLine: {
				lineStyle: {
					color: '#fff'
				}
			},
			//data: ['2018-11-14', '2018-11-15', '2018-11-16', '2018-11-17', '2018-11-18', '2018-11-18', '2018-11-20', '2018-11-21', '2018-11-22', '2018-11-23', '2018-11-24', '2018-11-25']
			data: time
		}, {
			axisLine: {
				show: false, //上横轴
				lineStyle: {
					color: 'red',
				}
			},

		}],
		yAxis: [{
			axisLabel: {
				show: true,
				formatter: '{value}'
			},
			splitLine: {
				lineStyle: {
					color: 'rgba(255,255,255,.1)'
				}
			},
			axisLine: {
				lineStyle: {
					color: '#fff'
				}
			},
		}],
		series: [{
			name: "一般事件",
			type: 'line',
			smooth: true,
			symbol: 'circle',
			symbolSize: 5,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 3,
					borderColor: 'rgba(245,106,124)',
					type: 'solid' //'dotted'虚线 'solid'实线
				}
			},
			/*areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0.99,
						color: 'rgba(222,103,244, 0.2)'
					}, {
						offset: 0.9,
						color: 'rgba(222,103,244, 0.3)'
					}, {
						offset: 0.7,
						color: 'rgba(222,103,244, 0.5)'
					}, {
						offset: 0.5,
						color: 'rgba(222,103,244, 0.7)'
					}, {
						offset: 0.3,
						color: 'rgba(222,103,244, 0.8)'
					}, {
						offset: 0.1,
						color: 'rgba(222,103,244, 0.99)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.9)',
					shadowBlur: 10
				}
			},*/
			itemStyle: {
				normal: {
					color: '#0feb8b', //预测走势
					borderColor: '#0feb8b',
					borderWidth: 12
				}
			},
//			data: [12, 23, 32, 37, 43, 20, 50, 75, 30, 45, 32, 35]
			data: trendData
		},{
			name: "报警事件",
			type: 'line',
			smooth: true,
			symbol: 'circle',
			symbolSize: 5,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 3,
					borderColor: 'rgba(245,106,124)',
					type: 'solid' //'dotted'虚线 'solid'实线
				}
			},
			/*areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0.99,
						color: 'rgba(245,106,124, 0.2)'
					}, {
						offset: 0.9,
						color: 'rgba(245,106,124, 0.3)'
					}, {
						offset: 0.7,
						color: 'rgba(245,106,124, 0.5)'
					}, {
						offset: 0.5,
						color: 'rgba(245,106,124, 0.7)'
					}, {
						offset: 0.3,
						color: 'rgba(245,106,124, 0.8)'
					}, {
						offset: 0.1,
						color: 'rgba(245,106,124, 0.99)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.9)',
					shadowBlur: 10
				}
			},*/
			itemStyle: {
				normal: {
					color: "#ffa500", //预测走势
					borderColor: "#ffa500",
					borderWidth: 12
				}
			},
//			data: [12, 23, 32, 37, 43, 20, 50, 75, 30, 45, 32, 35]
			data: trendData1
		},{
			name: "跳闸事件",
			type: 'line',
			smooth: true,
			symbol: 'circle',
			symbolSize: 5,
			showSymbol: false,
			lineStyle: {
				normal: {
					width: 3,
					borderColor: 'rgba(245,106,124)',
					type: 'solid' //'dotted'虚线 'solid'实线
				}
			},
			/*areaStyle: {
				normal: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0.99,
						color: 'rgba(145,136,154, 0.2)'
					}, {
						offset: 0.9,
						color: 'rgba(145,136,154, 0.3)'
					}, {
						offset: 0.7,
						color: 'rgba(145,136,154, 0.5)'
					}, {
						offset: 0.5,
						color: 'rgba(145,136,154, 0.7)'
					}, {
						offset: 0.3,
						color: 'rgba(145,136,154, 0.8)'
					}, {
						offset: 0.1,
						color: 'rgba(145,136,154, 0.99)'
					}], false),
					shadowColor: 'rgba(0, 0, 0, 0.9)',
					shadowBlur: 10
				}
			},*/
			itemStyle: {
				normal: {
					color: "#ff0000", //预测走势
					borderColor: "#ff0000",
					borderWidth: 12
				}
			},
//			data: [12, 23, 32, 37, 43, 20, 50, 75, 30, 45, 32, 35]
			data: tiaozhaArr
		}]
	};
	setTimeout(function() {
		myChart3.setOption(option3);
	}, 500);
	$(document).ready(function() {
		myChart3.resize();
	});
	window.addEventListener("resize", function() {
		myChart3.resize();
	})
}
//告警走势结束

//按天，按月，按年，查询 结束

//告警(严重/普通) 表格开始
function alarmStyleFunc(detailArr) {
	var detailStr = JSON.stringify(detailArr);
	localStorage.setItem("detailStr", detailStr);
	
	if(detailArr==null && detailArr == undefined){
		$('#EAAlarmTableBox').html('');
	}else{
		//alert("告警(严重/普通) 表格 detailArr="+detailArr.length);
		$('#EAAlarmTableBox').html('<table id="EAAlarmTable"></table>');
		taleFunc();
	}
	function taleFunc(){
		$('#EAAlarmTable').bootstrapTable({
			data:detailArr,
			/*data: [{
					"id": "2018-11-16",
					"Etime":"2018-11-16",
					"name": "2018-11-16",
					"deptName": "严重",
					"company": "威默电力",
					"currentValue": 232,
				},{
					"id": "2018-11-16",
					"Etime":"2018-11-16",
					"name": "2018-11-16",
					"deptName": "严重",
					"company": "威默电力",
					"currentValue": 232,
				}
				
			],*/
			columns: [{
					field: 'id',
					title: '时间',
				},
				
				{
					field: 'company',
					title: '标题',
				},
				
				{
					field: 'deptName',
					title: '内容'
				}

			]
		});
		setTrColrFunc()
	}
}
//告警(严重/普通) 结束
//告警排行开始
function alarmRankFunc(rankArr) {
	var rankStr = JSON.stringify(rankArr);
	localStorage.setItem("rankStr", rankStr);
	$('#EARankTable').bootstrapTable({
		data:rankArr,
		/*data: [{
				"rank": 1,
				"time":"2018-11-16",
				"region": "贵安新区",
				"site": "贵安新区XXXX",
				"number": "235",
				"content": "进线总电流超过········",
			},{
				"rank": 2,
				"time":"2018-11-16",
				"region": "贵安新区",
				"site": "贵安新区XXXX",
				"number": "235",
				"content": "进线总电流超过········",
			}
			
		],*/
		columns: [{
				field: 'rank',
				title: '排行',
			},
			{
				field: 'time',
				title: '时间',
			},
			{
				field: 'number',
				title: '次数'
			}
		]
	});
}
//告警排行 结束

function openLayerFunc(id){
	var tHeight = 0;
	var windowH = $(window).height();     //浏览器时下窗口可视区域高度
	var detail = localStorage.getItem("detailStr");
	var rankStr = localStorage.getItem("rankStr");
	var detailArr = JSON.parse(detail);
	var rankArr = JSON.parse(rankStr);
	//========
	var jfpg = $("#JFPG").attr("id");
	
	console.log("推送消息id="+jfpg);
	var area = [];
	
	var gjph = $("#gjph").attr("id");
	var fenlei = $("#fenlei").attr("id");
	console.log("推送消息id="+gjph+'--'+"实时告警id=:"+fenlei);
	var area = [];
	var title = '';
	if(id == gjph){//当点击推送消息的详情时的操作
		if(rankArr&&rankArr.length>0){//计算告警排行数据条数设置弹框高度
			tHeight = (rankArr.length)*37+105;
			if(tHeight>windowH){
				tHeight=windowH;
			}
			
		}else{
			tHeight= 138;
		}
		//alert("tHeight="+(tHeight)+"str="+tHeight.toString());
		area = ['1000px',tHeight.toString()+'px'];
		
		ifFunc('告警排行',area,gjph);
		setSessionfunc('','',gjph);
	}
	if(id == fenlei){//当点击实时告警推送的详情时的操作
		if(detailArr && detailArr.length > 0){//计算数据条数设置弹框高度
			tHeight = (detailArr.length)*37+33;
			if(tHeight>windowH){
				tHeight=windowH-400;
			}
			
		}else{
			tHeight = 138;
		}
		//alert("tHeight="+(tHeight)+"str="+tHeight.toString());
		area = ['1000px',tHeight.toString()+'px'];
		
		ifFunc('实时告警详情',area,fenlei);
		setSessionfunc('','',fenlei);
	}
	function ifFunc(title,area,ID){
		layer.open({
			type: 2,
			title: false,
			//title:'实时告警详情',
			title:title,
			center:"center",
			closeBtn: 1,
			area: ['1010px', '500px'],
			resize:false,//是否允许拉伸
			//area: area,
			shadeClose: true,
			skin:"myskin",
			scrollbar:false,
			content: './tanKuang.html'
		});
		//layer 弹框标题、关闭x样式
		$('.myskin').css({
			'background':'#07256b'
		})
		$(".myskin a.layui-layer-ico").text('×').css({
			'color':'#fff',
			'fontSize':'2rem',
			'margin-top': '-15px',
			'background':'none'
		});
		
		$(".layui-layer-title").css({'color':'#fff',});
	}
}

//值班人员
//onlineFunc();
function onlineFunc(){
	//alert("online zhandianid = "+zhandianid);
	// unitid 是站点ID
	// var url="/bigtongji/getRotaList?unitid=000000000001";
	var url="/bigtongji/getRotaList?unitid="+zhandianid;
	 $.ajax({
	     cache: true,
	     type: "POST",
	     url:url,
	     data:"",
	     async: false,				   
	     success: function(data){
        // alert(data);
        console.log(data);
        var dataObj=eval("("+data+")");// 转换为json对象
        // alert(dataObj);
        // alert(dataObj);
        if(dataObj.rows.length>0){
    		 $("#onlineNotice").html('');
    		 for (var i = 0; i < dataObj.rows.length; i++) {
         		var cid= dataObj.rows[i].cid;
         		var name= dataObj.rows[i].rname;
         		var phone= dataObj.rows[i].phoneCode;
         		//alert(cid);
         		//alert("cid="+cid+"name="+name+"phone="+phone);
        		 $("#onlineNotice").append('<li><span>👨‍⚖️&nbsp;&nbsp;<span id="onlineName1">'+name+'</span>&nbsp;电话：</span><span>'+phone+'</span></li>');
         	  }
    	  }
    	 if(dataObj.rows.length==0){
    		$("#onlineNotice").html(''); 
    	 }
	     }
	 });

}
//值班人员结束

//返回上一级跳转逻辑处理
function bachFunc(){
	var urlsStr = localStorage.getItem("urls");
	var ss = JSON.parse(urlsStr);
	if(ss.sanji != undefined &&  ss.sanji !=''){
    	//alert(ss.sanji);
		window.location.href = './specificHome.html';
    	return;
    }
    if(ss.erji != undefined && ss.erji !=''){
    	//alert(ss.erji);
    	window.location.href = './intlgMonitor.html';
	    return;
    }if(ss.yiji != undefined &&  ss.yiji !=''){
    	//alert(ss.yiji);
	    window.location.href = './pro_Home.html';
	    return;
    }else{
	   //alert(222)
    }
}

//判断告警信息弹框的事件类型 设置行颜色
function setTrColrFunc(){
	var trNum = $("#EAAlarmTable tbody tr");
	//alert($("#EAAlarmTable tbody tr").eq(1).text());
	
	for(var k=0;k<trNum.length;k++){
		var tdStr1 = $("#EAAlarmTable tbody tr").eq(k).text();
		//alert("tdStr1 = "+tdStr1);
		if(tdStr1.indexOf("报警事件") >= 0 ) {
		    $("#EAAlarmTable tbody tr").eq(k).css('color','orange')
		}if(tdStr1.indexOf("跳闸事件") >= 0 ) {
		    $("#EAAlarmTable tbody tr").eq(k).css('color','red')
		}if(tdStr1.indexOf("一般事件") >= 0 ) { 
		    $("#EAAlarmTable tbody tr").eq(k).css('color','#0feb8b')
		}
	}
}